<?php

/* @var $this yii\web\View */
$this->registerJsFile('/js/jquery.min.js');
$this->registerJsFile('/js/user/goodslist.js');
?>
<table class="layui-table no-b" lay-skin="line">
 <colgroup>
    <col>
    <col width="80">
    <col width="200">
    <col width="100">
    <col>
  </colgroup>
  <thead>
    <tr>
      <th>ID</th>
      <th>图片</th>
      <th>名称</th>
      <th>价格</th>
      <th>分类</th>
      <th>状态</th>
      <th>添加时间</th>
      <th>操作</th>
    </tr> 
  </thead>
  <tbody>
	<?php foreach($data['goodsdata'] as $goods){ ?>  
    <tr>
      <td><?= $goods['id'] ?></td>
      <td><a href="/goodsdetail?goods_id=<?= $goods['id'] ?>"><img src="<?= $goods['img'] ?>"/></a></td>
      <td><a href="/goodsdetail?goods_id=<?= $goods['id'] ?>"><?= $goods['name'] ?></a></td>
	  <td class="red">¥<strong class="f14"><?= $goods['price'] ?></strong></td>
	  <td></td>
	  <td><span class="layui-badge layui-bg-green <?php if($goods['status']==2){ //已下架的商品才能编辑?> layui-bg-gray<?php }?>"><?= $data['status_arr'][$goods['status']] ?></span></td>
	  <td><?= date('Y-m-d', $goods['order_endtime']); ?></td>
	  <td>
			<a href="/goodsdetail?goods_id=<?= $goods['id'] ?>" class="layui-btn layui-btn-xs layui-btn-normal">详细信息</a>
			<a class="layui-btn layui-btn-xs layui-btn-primary goods-delete" data-id="<?= $goods['id']?>">删除</a> </td>
    </tr>
	<?php } ?>
  </tbody>
</table>

<div class="block mt15 text-c">
	<div class="layui-box layui-laypage layui-laypage-default">
		<a  class="layui-laypage-prev <?= $data['page_no']=='1' ? 'layui-disabled' : '';?>" data-pageno="<?= $data['page_no'] ?>">上一页</a>
		
		<?php for($i=1;$i<=$data['pagenums'];$i++){ ?>
			<a class="pageno <?= $i==$data['page_no'] ? ' layui-laypage-curr ' : ''; ?>" href="javascript:;" data-pageno="<?= $data['page_no'] ?>" data-page="<?= $i ?>"><?= $i ?></a>
		<?php } ?>
		
		<a href="javascript:;" class="layui-laypage-next <?= $data['page_no']==$data['pagenums'] ? 'layui-disabled' : '';?>" data-pageno="<?= $data['page_no'] ?>"  data-pagenums="<?= $data['pagenums'] ?>">下一页</a>
	</div>
</div>
	
	
<script>
	$('.pageno').on('click',function(){
		var page = $(this).attr('data-page');
		window.location.href = '/user/goodslist?page_no='+page;
		console.log(page);		
		});
	$('.layui-laypage-prev').on('click',function(){
		var page = $(this).attr('data-pageno');
		if(page == 1){
			return false;
		}
		else{
			page = page-1;
		}
		window.location.href = '/user/goodslist?page_no='+page;
	});
	
	$('.layui-laypage-next').on('click',function(){
		var page = $(this).attr('data-pageno');
		var pagenums = $(this).attr('data-pagenums');
		if(page == pagenums){
			return false;
		}
		else{
			page = parseInt(page)+1;
		}
		window.location.href = '/user/goodslist?page_no='+page;
	});
  </script>
